/**
 * Project Name:九色鹿
 * File Name:SimpleZhName.java
 * Package Name:com.fxp.project.jiuselu.commons.name.zh
 * Date:2020年04月06日 11:24
 * Copyright (c) 2020, Jason.Wang All Rights Reserved.
 */
package com.fxp.project.jiuselu.commons.name.zh;

import com.fxp.project.jiuselu.commons.name.IRandomName;
import lombok.extern.log4j.Log4j2;

import java.io.UnsupportedEncodingException;
import java.util.Random;

/**
 * ClassName:SimpleZhName<br/>
 * Function: 中文名称实现类<br/>
 * Date:2020年04月06日 11:24<br/>
 *
 * @author Jason.Wang
 * @version 1.0.0.0
 * @see
 * @since JDK1.8
 */
@Log4j2
public class SimpleZhName implements IRandomName {
    private Random random;

    /**
     * 构造方法
     */
    public SimpleZhName() {
        random = new Random();
    }

    /**
     * getFirstNameDesign: 获取中文名称的数据<br/>
     *
     * @return
     * @author Jason.Wang
     * @createTime 2020/4/6 11:34
     */
    public String[] getFirstNameDesign() {
        return SourceZh.firstNameDesign;
    }

    /**
     * designFirstName: 数组中随机下标的字符串<br/>
     *
     * @return
     * @author Jason.Wang
     * @createTime 2020/4/6 11:36
     */
    public String designFirstName() {
        //[0,n)
        int i = random.nextInt(SourceZh.firstNameDesign.length);
        return SourceZh.firstNameDesign[i];
    }

    /**
     * designSimpleLastName: 去掉了相当多的繁体字，随机生成一个汉字<br/>
     *
     * @return
     * @author Jason.Wang
     * @createTime 2020/4/6 11:36
     */
    private String designSimpleLastName() {
        StringBuilder sBuilder = new StringBuilder();
        int lastLen = 1 + random.nextInt(2);
        for (int i = 0; i < lastLen; i++) {
            int hight = 176 + random.nextInt(39);
            int low = 161 + random.nextInt(93);
            byte[] han = new byte[2];
            han[0] = Integer.valueOf(hight).byteValue();
            han[1] = Integer.valueOf(low).byteValue();

            try {
                sBuilder.append(new String(han, "gbk"));
            } catch (UnsupportedEncodingException e) {
                log.warn(">>>", new Throwable(e));
            }
        }
        return sBuilder.toString();
    }

    /**
     * getFullName: 获取全名<br/>
     *
     * @return
     * @author Jason.Wang
     * @createTime 2020/4/6 11:21
     */
    @Override
    public String getFullName() {
        return designFirstName() + designSimpleLastName();
    }

    /**
     * getSplitName: 数组 [姓,名]<br/>
     *
     * @return
     * @author Jason.Wang
     * @createTime 2020/4/6 11:22
     */
    @Override
    public String[] getSplitName() {
        String[] splitName = {designFirstName(), designSimpleLastName()};
        return splitName;
    }

    /**
     * getSimpleName: 中文名称 <br/>
     *
     * @return
     * @author Jason.Wang
     * @createTime 2020/4/6 11:22
     */
    @Override
    public String getSimpleName() {
        return designSimpleLastName();
    }
}
